import React from 'react';
import * as Icon from '@ant-design/icons';
import Clipboard from 'clipboard';

/** copyToClipboard (复制到剪贴板)方法说明
* @author: JasonStandFor
* @param {string} copyText - 传入需要被复制的文本内容
* @return undefined
* @example:
copyToClipboard('测试复制文本内容');
* */
export const copyToClipboard = (copyText = '复制内容: 剪贴板') => {
  const dom = window.document.createElement('div');
  dom.classList.add('behavior-copy-text');
  dom.setAttribute('data-clipboard-text', copyText);
  window.document.body.appendChild(dom);
  new Clipboard('.behavior-copy-text');
  dom.click();
  window.document.body.removeChild(dom);
};

// 获取本地时间
export const localTime = (nowDate) => {
  let date;
  nowDate ? date = new Date(nowDate) : date = new Date();
  const y = date.getFullYear()
  const m = date.getMonth() + 1
  const d = date.getDate()
  const h = date.getHours()
  const f = date.getMinutes()
  const s = date.getSeconds()
  const toDB = num => num < 10 ? '0' + num : num;
  return y + '-' + toDB(m) + '-' + toDB(d) + ' ' + toDB(h) + ':' + toDB(f) + ':' + toDB(s);
};

export const getAntdIcon = (name = 'CloudOutlined') => React.createElement(Icon[name]);
